package command;

import indexingSystem.Document;
import indexingSystem.IndexingSystem;

import java.io.File;
import java.util.Vector;

public class ReadFolder implements Command{
	public void execute(Vector<String> args) throws Exception {
		if (args == null)
			throw new Exception(getCommandUsage());
		if (args.size() > 1)
			throw new Exception(getCommandUsage());
		File file = new File(args.get(0));
		File [] fileList = null;
		if (!(file.isDirectory() && file.canExecute()))
			throw new Exception(file.getAbsolutePath()+": Given path is not a readable directory.");
		
		fileList = file.listFiles();	
		for(File document : fileList)
			IndexingSystem.addDocument(new Document(document.getAbsolutePath()));
	}
	public String getCommandName(){
		return "readfolder";
	}
	public boolean commandHasArgs() {
		return true;
	}
	public String getCommandUsage() {
		return getCommandName()+" <directory>";
	}	
}
